﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System;
using System.Text.RegularExpressions;
public class Panel_0 : BasePanel {

	// Use this for initialization
    public Text showText;
    String userId;
    public GameObject prefab;

	void Start () {
		//初始化
		TestModel.Instance.Init();
        //最好不要直接写字符串，用枚举比较好
        Dispatcher.Instance.AddEventListener(GMConfig.EventType.NCMyTestChange, MyTest);
		Dispatcher.Instance.AddEventListener("myTest",MyTest2,0);
		Dispatcher.Instance.AddEventListener("myTest2",MyTest2);
        GameObjectPoolMgr.InitPool("Test", prefab);
	}
	
	// Update is called once per frame
	void Update () {
		
	}

    public void OnClick(string panelType)
    {
        //zipHelper
        //string str = "";
        //int i = System.Text.Encoding.Default.GetBytes(str).Length;
        //Debug.Log(i);    
        //str = ZipHelper.GZipCompressString(str);
        //i = System.Text.Encoding.Default.GetBytes(str).Length;
        //Debug.Log(str);
        //Debug.Log(i);
        //str = ZipHelper.GZipDecompressString(str);
        //i = System.Text.Encoding.Default.GetBytes(str).Length;
        //Debug.Log(i);
        //Debug.Log(str);

        //对象池使用实例
        //for (int i = 0; i < 10; i++)
        //{
        //    var _object = GameObjectPoolMgr.GetObject("Test");
        //    GameObjectPoolMgr.PutObject("Test", _object);
        //}
        //GameObjectPoolMgr.Count("Test");
        //GameObjectPoolMgr.Useable("Test");
        //多语言使用
        Dictionary<string, object> data = new Dictionary<string, object>();
        data.AddOrReplace("age", 12);
        data.AddOrReplace("name", 12);
        LTLocalization.ManualSetLanguage(SystemLanguage.English);
        string text = LTLocalization.GetText("Test",data);
        Debug.Log(text);
        //长连接访问示例
        // if (panelType == "Panel_1") MyPomeloMgr.GetPomelo("sys_0");
        // if (panelType == "Panel_2") MyPomeloMgr.GetPomelo("sys_0").sendMsg("123456 .......");
        // if (panelType == "Panel_3") MyPomeloMgr.GetPomelo("sys_0", "789").sendMsg("789 .......");

        //访问原生接口
        // if(panelType == "Panel_1") showText.text = NativeUtils.Instance.Toast("这就是我要提示的内容！");
        // if (panelType == "Panel_2") showText.text = NativeUtils.Instance.Shock();
        // if (panelType == "Panel_3") showText.text = NativeUtils.Instance.Other();

        //工具类示例
        //var str = Utils.Encode64("今天天气不错 adsf 123");
        //Debug.Log(str);
        //var str2 = Utils.Decode64(str);
        //Debug.Log(str2+"  "+str); 

		//网络访问DEMO
        //var network = NetWorkManager.Instance.GetNetInstance();
        //var data = NetWorkManager.Instance.GetData("user_c", "getFollowCode");
        //data.Add("openId", "oqsaSuG9xtcrPSgx0ZcWfI7m-NxI");
        //network.Request(this, data, CallBack);

		//UI使用DEMO
        // UIPanelType _panelType = (UIPanelType)System.Enum.Parse(typeof(UIPanelType), panelType);
        // UIManager.Instance.pushPanel(_panelType);

		//事件派发DEMO
        //ArrayList a = new ArrayList();
        //a.Add("adfdf");
        //a.Add("123");
        //a.Add("d");
        //a.Add("456546");
        //a.Add("134678");
        //Dispatcher.Instance.DispatchEvent(GMConfig.EventType.NCMyTestChange, "哈哈哈哈");
        //Dispatcher.Instance.DispatchEvent("myTest2", a);
    }
	//网络接口返回后回调
	public void CallBack(object err,object result){
		var code = TestModel.Instance.get("code");		
		Debug.Log("err:"+err.ToString()+"result:"+result.ToString());
	}
	public void MyTest(object param){
		Debug.Log("MyTest");
		if(param != null) Debug.Log(param.ToString());
	}
	public void MyTest2(object param){
		Debug.Log("MyTest2");
		if(param != null) Debug.Log(param.ToString());
	}
}
